﻿//父ID
var parID="";
var pageSize = 15;

//点击回复Reply this topic按钮
function ClickRTBT(id)
{
    parID=id;
    if(__P_M==""){
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+WWWHost+"/groups/"+GroupID+"/topic/"+TopicID+".htm";
        return;
    }
	$scroller$("btnSave",100);
	FCKeditorAPI.GetInstance('txtDesc1').Focus();
}
//回复帖子
function ReplyTopic()
{
    if(__P_M==""){
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+WWWHost+"/groups/"+GroupID+"/topic/"+TopicID+".htm";
        return;
    }
    var valDesc = "";//内容
    var oEditor = FCKeditorAPI.GetInstance('txtDesc1') ;
    try{valDesc=oEditor.GetXHTML(true);}catch(e){}    
    if(valDesc.length<3 || valDesc.length>1000)
    {
        $("ErrorDesc").style.display = "";
        return;
    }
    $("ErrorDesc").style.display = "none";
    $("btnSave").disabled = true;     
    WebServices.WWW.Groups.ReplyTopic(TopicID,parID,valDesc,pageSize,onsuccTopic,webFailure,"DReT");
    parID="";
    oEditor.EditorDocument.body.innerHTML=''; 
}
//删除回复
function DelReplyTopic(tid)
{
    if(__P_M==""){
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+WWWHost+"/groups/"+GroupID+"/topic/"+TopicID+".htm";
        return;
    }
    showProgressBar(false,true);
    $("$divIput$").style.display = "none";
    var body="<p><strong>"+delRpBody+"</strong></p><br/><div class='Popup_button'><input type='button' value='"+C0069+"' id='addOkButton' class='button' onclick=\"opWSDelRT('"+tid+"')\" />&nbsp;&nbsp;<input type='button' value='"+gCancel+"' id='addCancelButton' class='buttong' onclick='webFailure()'/></div>";
    var obj = {}
    $ShowMessageBox$(delTitle,body,obj,webFailure,400);
}
//执行删除回复方法
function opWSDelRT(id)
{
    WebServices.WWW.Groups.DelReplyTopic(id,pIndex,pageSize,onsuccTopic,webFailure,"DReT");
}
//删除帖子
function DelTopic()
{
    if(__P_M==""){
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+WWWHost+"/groups/"+GroupID+"/topic/"+TopicID+".htm";
        return;
    }
    showProgressBar(false,true);
    $("$divIput$").style.display = "none";
    var body="<p><strong>"+delBody+"</strong></p><br/><div class='Popup_button'><input type='button' value='"+C0069+"' id='addOkButton' class='button' onclick=\"opWebSerDelT()\" />&nbsp;&nbsp;<input type='button' value='"+gCancel+"' id='addCancelButton' class='buttong' onclick='webFailure()'/></div>";
    var obj = {}
    $ShowMessageBox$(delTitle,body,obj,webFailure,400);
}
//执行删除帖子方法
function opWebSerDelT()
{
    WebServices.WWW.Groups.DeleteTopic(TopicID,onsuccTopic,webFailure,"DT");    
}
function onsuccTopic(result,op)
{
    $EndMessageBox$();
    showProgressBar(true);
    if(op=="DT"&&result.State)//删除帖子
    {
        top.location=WWWHost+"/groups/"+GroupID;     
    }
    else if(op="DReT"&&result.length>1)//删除回复
    {
        $("TopicsCount").innerHTML=result[0].RecordCount;
        RendPage(result[0],"divPage",strHome,strPre,strLast,strNext,strSel,strUnSel);
        RendRTopicList(result[1],"TopicList");
    }
    else
    {
        showProgressBar(false);
    }
    $("btnSave").disabled = false;    
}
//替换数据
function RendRTopicList(list,divID)
{
    var domDiv =$(divID);    
    if(domDiv!=null)
    {
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");
        }   
        if($("RTopicItem")==null) return;                   
        var item= $("RTopicItem").innerHTML;
        var listBuilder = new Sys.StringBuilder();
        gLastCount = list.length;            
        for (var index = 0; index < gLastCount; index++) 
        {              //GetFormatDate(sFormat,sDateText,sDate)
            var obj = list[index];                     
            var tmp = item.replace(/\$Avatar\$/gi,"<img src=\""+(obj.Avatar==""?"/Images/No_pic.gif":obj.Avatar)+"\" alt=\""+obj.NickName+"\"/>").replace(/\$Memberno\$/gi,obj.Memberno).replace(/\$NickName\$/gi,obj.NickName);
            tmp = tmp.replace(/\$Delete\$/gi,TMR==1?"<a href='javascript:void(0);' title='"+Delete+"' onclick='DelReplyTopic(\"" + obj.TopicID.toString() + "\")'><img src='/Images/gaction_delete.gif' align='absmiddle' border='0'></a>&nbsp;<a href='javascript:void(0);' title='"+Delete+"' onclick='DelReplyTopic(\"" + obj.TopicID.toString() + "\")'>"+Delete+"</a>" : "");
            tmp = tmp.replace(/\$ParentContent\$/gi,obj.ParentContent).replace(/\$Topic\$/gi,obj.Topic).replace(/\$DiffDate\$/gi,GetFormatDate(gDateFormat,gStrDate,obj.DiffDate));
            tmp = tmp.replace(/\$TopicID\$/gi,obj.TopicID);
            listBuilder.append(tmp);
        }
        var sTemp = listBuilder.toString();
        domDiv.innerHTML = sTemp;             
    }
    showProgressBar(false);
}
//调用webService方法失败
function webFailure()
{
    $EndMessageBox$();
    $("btnSave").disabled = false;
}